<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="12">
        <el-card class="main">
          <Mobile :backgroundImg="dataForm.bgroundImg" class="mobile">
            <div class="yqm">
              <img style="height: 100%; width: 100%" v-if="dataForm.qrCode" :src="dataForm.qrCode" alt="">
            </div>
            <el-button type="primary" class="btn">点击联系</el-button>
          </Mobile>  
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="card" header="配置">
          <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
            <el-form-item label="标题" prop="title">
              <el-input v-model="dataForm.title" placeholder="标题"></el-input>
            </el-form-item>
            <el-form-item label="描述" prop="description">
              <el-input v-model="dataForm.description" placeholder="描述"></el-input>
            </el-form-item>
            <el-form-item label="二维码" prop="qrCode">
              <el-input v-model="dataForm.qrCode" placeholder="二维码"></el-input>
            </el-form-item>
            <el-form-item label="跳转链接" prop="link">
              <el-input v-model="dataForm.link" placeholder="跳转链接"></el-input>
            </el-form-item>
            <el-form-item label="邀请链接" prop="inviteUrl">
              <el-input v-model="dataForm.inviteUrl" placeholder="邀请链接"></el-input>
            </el-form-item>
            <el-form-item label="状态" prop="status">
              <ren-radio-group v-model="dataForm.status" dict-type="status"></ren-radio-group>
            </el-form-item>
          </el-form>
          <template #footer>
            <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
            <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
          </template>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import Mobile from './components/mobile.vue'
import baseService from "@/service/baseService";
import { useI18n } from "vue-i18n";
import { ElMessage } from "element-plus";
const { t } = useI18n();

const visible = ref(false);
const dataFormRef = ref();
const emit = defineEmits(["refreshDataList"]);

const dataForm = reactive({
  id: "",
  title: "",
  description: "",
  bgroundImg: "https://img.ixintu.com/download/jpg/202004/06abeff203c15f92be90def94ee625e5_800_1422.jpg%21con0",
  qrCode: "",
  link: "",
  inviteUrl: "",
  times: "",
  remark: "",
  status: "true",
});

const rules = ref({
});

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    if (!valid) {
      return false;
    }
    (!dataForm.id ? baseService.post : baseService.put)("/plug/pluginvite", dataForm).then((res) => {
      ElMessage.success({
        message: t("prompt.success"),
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

</script>

<style lang="less" scoped>
.main {
  height: 100%;
  margin: 0 auto;
  .mobile {
    text-align: center;
    margin: 0 auto;
    overflow: auto;
    .yqm {
      width: 150px;
      height: 150px;
      text-align: center;
      margin: 300px auto 0;
    }
    .btn {
      margin-top: 15px;
    }
  }
}


</style>